package com.wuzao.ThreadLocalTest;

public class ThreadLocalTest {
    public static void main(String[] args) {
        System.out.println(MyThreadLocal.CURRENT_USER.get());
//        System.out.println(MyThreadLocal.CURRENT_USER.get().getId());

        // 启动两个线程
        Thread thread1 = new Thread(() -> {
            UserVO userVO = new UserVO();
            userVO.setId(1);
            MyThreadLocal.CURRENT_USER.set(userVO);
            extracted("Thread 1: ");
        });

        Thread thread2 = new Thread(() -> {
            UserVO userVO = new UserVO();
            userVO.setId(2);
            MyThreadLocal.CURRENT_USER.set(userVO);
            extracted("Thread 2: ");
        });

        thread1.start();
        thread2.start();

    }

    private static void extracted(String x) {
        System.out.println(x + MyThreadLocal.CURRENT_USER.get().getId());
    }
}
